package com.bean.qq.service;

import com.bean.qq.entity.CreditCardApplyInfo;
import com.bean.qq.entity.Order;
import lombok.extern.slf4j.Slf4j;
import org.kie.api.KieBase;
import org.kie.api.command.Command;
import org.kie.api.command.KieCommands;
import org.kie.api.runtime.ExecutionResults;
import org.kie.api.runtime.KieSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 * 规则业务类
 * @author xuyisu
 * @date 2020/05/10
 */
@Service
@Slf4j
public class RuleService {
    @Autowired
    private KieBase kieBase;
//    @Autowired
//    private KieClientService kieClientService;
    //调用Drools规则引擎实现信用卡申请
    public CreditCardApplyInfo creditCardApply(CreditCardApplyInfo creditCardApplyInfo){
        KieSession session = kieBase.newKieSession();
        session.insert(creditCardApplyInfo);
        session.fireAllRules();
        session.dispose();
        return creditCardApplyInfo;
    }

    @PostConstruct
    public void init() {

        log.info("初始化KieClientService");
//        Order order=new Order();
//        order.setAmount(230);
//        KieCommands kieCommands = kieClientService.getKieCommands();
//        List<Command<?>> kieCommandList = kieClientService.getKieCommandList();
//        kieCommandList.add(kieCommands.newInsert(order,"order"));
//        ExecutionResults executionResults = kieClientService.executeCommands(kieCommandList, kieCommands);

//        log.info("result:{}",executionResults);
    }
}
